package com.tledu.mvc02.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 测试request,response,session等
 * @author Antg
 * @date 2021/8/12  0:45
 */
@Controller
@RequestMapping("/test3")
public class UserController3 {
    //多个接口映射到一个方法上
    @GetMapping({"/m1","m11"})
    public void m1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println(req.getRemoteHost());
        resp.sendRedirect("https://www.baidu.com/");
    }
    //向页面传递数据(仅限jsp)
    @GetMapping("/m2")
    public String m2(String username, Model model){
        model.addAttribute("username",username);
        return "user/add";
    }



}
